#ifndef LAN_SERVER_H_
#define LAN_SERVER_H_

#include <SFML/System.hpp>

#include "../core/smart_ptr.hpp"

#include "connection.hpp"

namespace lge2d
{
namespace lan
{
namespace server
{

/**
 * Класс, используемый для получения входящих соединений клиентов.
 */
class Server
{
public:
	enum ServerState
	{
		ServerIsStarted,
		ServerIsStarting,
		ServerIsWorking,
		ServerIsStopping,
		ServerIsStopped
	};

public:
	Server();
	virtual ~Server();

	void SetPort(unsigned short port);
	unsigned short GetPort() const;
	//
	void Start();
	void Stop();
	//
	ServerState GetState() const;
	unsigned GetClientsCount() const;
	//
	void Update(float dt);

private:
	void Initialize();
	void Terminate();

private:
	typedef SmartPtr<Connection> ConnectionPtr;

	unsigned short m_port;
	ServerState m_state;
	sf::SocketTCP m_socket_listener;
	std::vector<ConnectionPtr> m_client_connections;
};

} /* namespace server */
} /* namespace lan */
} /* namespace lge2d */
#endif /* LAN_SERVER_H_ */
